﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FlyingAPI;

namespace TagSpider
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void bnLogin_Click(object sender, EventArgs e)
        {
            String validate = validateInput();

            if (String.IsNullOrEmpty(validate))
            {
                Form1 f = new Form1();
                String url = "http://" + txServer.Text + "/";
                f.Url = url;
                TagSpiderController controller = TagSpiderController.getInstance(f.WritelnLog);
                controller.FlyingPig.setConnect(url);
                f.SearchJobs = controller.FlyingPig.requestSearchJobs(10);
                this.Hide();
                f.ShowDialog();
                this.Close();
            }
            else
            {
                // 提示出错
                MessageBox.Show(validate, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private String validateInput()
        {
            if (String.IsNullOrEmpty(txServer.Text))
            {
                return "Missing Server URL!";
            }

            if (String.IsNullOrEmpty(txUserID.Text))
            {
                return "Missing UserID!";
            }

            if (String.IsNullOrEmpty(txPassword.Text))
            {
                return "Missing Password!";
            }

            return "";
        }
    }
}
